package cn.stylefeng.guns.modular.time.controller;

import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.guns.modular.time.entity.FileTransfers;
import cn.stylefeng.guns.modular.time.model.request.FileTransfersRequest;
import cn.stylefeng.guns.modular.time.service.FileTransfersService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文件传输任务控制器
 */
@RestController
@ApiResource(name = "文件传输任务")
public class FileTransfersController {

    @Resource
    private FileTransfersService fileTransfersService;

    /**
     * 分页查询文件传输任务
     * @param searchText 搜索关键字
     * @param pageNo 页码
     * @param pageSize 每页大小
     * @param sortField 排序字段
     * @param sortOrder 排序方式 asc/desc
     * @return 分页数据
     */
    @GetResource(name = "分页查询-文件传输任务", path = "/fileTransfers/page")
    public ResponseData<PageResult<FileTransfers>> page(
            @RequestParam(required = false) String searchText,
            @RequestParam(required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(required = false, defaultValue = "20") Integer pageSize,
            @RequestParam(required = false) String sortField,
            @RequestParam(required = false) String sortOrder) {
        FileTransfersRequest request = new FileTransfersRequest();
        request.setSearchText(searchText);
        request.setPageNo(pageNo);
        request.setPageSize(pageSize);
        request.setSortField(sortField);
        request.setSortOrder(sortOrder);
        return new SuccessResponseData<>(fileTransfersService.findPage(request));
    }

    /**
     * 新增文件传输任务
     * @param request 请求体
     * @return 成功响应
     */
    @PostResource(name = "添加文件传输任务", path = "/fileTransfers/add")
    public ResponseData<Void> add(@RequestBody @Validated(FileTransfersRequest.add.class) FileTransfersRequest request) {
        fileTransfersService.add(request);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑文件传输任务
     * @param request 请求体
     * @return 成功响应
     */
    @PostResource(name = "编辑文件传输任务", path = "/fileTransfers/edit")
    public ResponseData<Void> edit(@RequestBody @Validated(FileTransfersRequest.edit.class) FileTransfersRequest request) {
        fileTransfersService.edit(request);
        return new SuccessResponseData<>();
    }

    /**
     * 删除文件传输任务
     * @param request 请求体
     * @return 成功响应
     */
    @PostResource(name = "删除文件传输任务", path = "/fileTransfers/delete")
    public ResponseData<Void> delete(@RequestBody @Validated(FileTransfersRequest.delete.class) FileTransfersRequest request) {
        fileTransfersService.delete(request);
        return new SuccessResponseData<>();
    }

    /**
     * 查看文件传输任务详情
     * @param request 请求体
     * @return 详情数据
     */
    @GetResource(name = "查看文件传输任务详情", path = "/fileTransfers/detail")
    public ResponseData<FileTransfers> detail(@Validated(FileTransfersRequest.detail.class) FileTransfersRequest request) {
        return new SuccessResponseData<>(fileTransfersService.detail(request));
    }
}